<template>
  <div class="fenlei">
    <van-search
      disabled
      shape="round"
      background="#fff"
      placeholder="请输入搜索关键词"
      @click="btn"
    />

    <!-- fenlei -->
    <div class="fenl">
      <van-sidebar v-model="activeKey">
        <van-sidebar-item
          v-for="item in categoryList"
          :key="item.id"
          :title="item.name"
          @click="fenlFn(item.id)"
        />
      </van-sidebar>
      <!-- 右边渲染 http://yanxuan.nosdn.127.net/92357337378cce650797444bc107b0f7.jpg-->
      <ul>
        <div>
          <img :src="banner_url" height="140px" width="95%" />
          <h5>{{ front_desc }}</h5>
        </div>

        <!-- 居家分类 -->
        <div class="mytitle">
          <span></span>
          <h3>{{ name }}</h3>
        </div>

        <!-- 列表 -->
        <van-grid :column-num="3">
          <van-grid-item
            v-for="item in subCategoryList"
            :key="item.id"
            :icon="item.wap_banner_url"
            :text="item.name"
          />
        </van-grid>
      </ul>
    </div>
  </div>
</template>
 
<script>
import { GetChannelDataApi, GetFenleiDataApi } from "@/https/http";
export default {
  data() {
    return {
      activeKey: 0,
      subCategoryList: [],
      categoryList: [],
      titles: [],
      banner_url: [],
      name: [],
      front_desc: [],
    };
  },
  methods: {
    btn() {
      this.$router.push("/category/popup");
    },
    fenlFn(id) {
      GetChannelDataApi().then((res) => {
        let index = this.activeKey;
        let { front_desc, banner_url, name } = res.data.categoryList[index];
        this.front_desc = front_desc;
        this.banner_url = banner_url;
        this.name = name;
        //   this.front_desc = "回家，放松身心";
      });
      this.diaoyong(id);
    },
    diaoyong(id) {
      GetFenleiDataApi({
        id,
      }).then((res) => {
        let { subCategoryList } = res.data.currentCategory;
        this.subCategoryList = subCategoryList;
        // console.log(res);
      });
    },
  },
  created() {
    GetChannelDataApi().then((res) => {
      let { categoryList, currentCategory } = res.data;
      this.categoryList = categoryList;
      this.subCategoryList = currentCategory.subCategoryList;
      let index = this.activeKey;

      let { front_desc, banner_url, name } = res.data.categoryList[index];
      this.front_desc = front_desc;
      this.banner_url = banner_url;
      this.name = name;
      //   this.front_desc = "回家，放松身心";
    });
  },
};
</script>
 
<style lang = "less" scoped>
.slide-enter,
.slide-leave-to {
  right: -100%;
}
.slide-enter-active,
.slide-leave-active {
  transition: right 0.5s linear;
}
.slide-enter-to,
.slide-leave {
  right: 0;
}
/* 分类 */
.fenl {
  width: 100%;
  background-color: #fff;
  height: 90vh;
  display: flex;
  .van-sidebar {
    width: 20%;
    background-color: #f7f8fa;
  }
  ul {
    width: 80%;
    div {
      width: 100%;
      position: relative;
      img {
        margin: 0 7px;
        border-radius: 5px;
        box-shadow: 0 0 6px #000;
        filter: brightness(0.5);
      }
      h5 {
        width: 100%;
        color: #fff;
        position: absolute;
        top: 48%;
        left: 0%;
        z-index: 222;
        text-align: center;
      }
    }
    .mytitle {
      width: 100%;
      height: 50px;
      position: relative;
      background: #fff;
      font-size: 16px;
      span {
        width: 50%;
        height: 2px;
        background-color: #ccc;
        position: absolute;
        margin: auto;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
      }
      h3 {
        width: 30%;
        height: 40px;
        background-color: #fff;
        position: absolute;
        margin: auto;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        line-height: 40px;
        text-align: center;
        color: #000;
      }
    }
  }
}
</style>